#ifndef ENCODE_H
#define ENCODE_H

#include <QFile>
#include <QByteArray>
#include <QBuffer>
#include <QThread>
#include <QSize>

extern "C"
{
#include <x264.h>
#include <libswscale/swscale.h>
}

class Encoder : public QObject
{
    Q_OBJECT
public:
    explicit Encoder(QSize resolution, QObject *parent = 0);
    ~Encoder();
    QByteArray getEncodedFrame(QImage, quint32);
    QImage doGrabFrame();
    QByteArray getFlvHeader(bool hasAudio = false, bool hasVideo = true);
    QByteArray getSequenceHeader();

private:
    QSize m_resolution;
    SwsContext *m_swCtx;
    x264_t *m_264enc;
    QByteArray flvTag(quint8 tagType, qint64 pts, qint64 dts, bool keyframe, quint8 *data, int size, bool sequenceHeader = false);
};

#endif // ENCODE_H
